package com.lianboke.link.ad.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ProgressBar;

import com.lianboke.link.ad.R;
import com.lianboke.link.ad.Views.MyListView;
import com.lianboke.link.ad.adapter.OrderCacheAdapter;
import com.lianboke.link.ad.dbmanager.OrderDetailsCacheUtils;
import com.lianboke.link.ad.entry.OrdetTypeTable;
import com.lianboke.link.ad.utils.DateUtil;
import com.lianboke.link.ad.utils.KLog;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 任务缓存页面
 */
public class OrderCacheActivit extends BaseActivity {

    @BindView(R.id.lv_order_1)
    public MyListView lv_order_1;


    @BindView(R.id.loading_progress)
    public ProgressBar loading_progress;

    @BindView(R.id.view_empty)
    public View view_empty;


    private List<OrdetTypeTable> orderTypeTableData = new ArrayList<OrdetTypeTable>();
    private OrderCacheAdapter orderCacheAdapter;//类型任务数据适配器


    //数据库操作订单详情
    private OrderDetailsCacheUtils orderDetailsCacheUtils ;

    private String strCurrentDate = "";//今天日期

    @Override
    public int getContentViewId() {
        return R.layout.activity_order_cache;
    }

    @Override
    public void initActivityParams(Bundle savedInstanceState) {
        setTitleBackShow(true);
        setTitleContent("今日需激活任务");

        orderDetailsCacheUtils =new  OrderDetailsCacheUtils(actContext);
        strCurrentDate = DateUtil.getCurDateStr("yyyy-MM-dd");

        //设置数据适配器
        orderCacheAdapter = new OrderCacheAdapter(actContext);
        lv_order_1.setAdapter(orderCacheAdapter);

    }

    @Override
    protected void onResume() {
        super.onResume();
        //获取任务列表数据
        showLoadingProgress();
        getOrderCacheListDatasByNetwork();
    }

    /**
     * 显示加载框
     */
    private void showLoadingProgress(){
        if(loading_progress!=null && loading_progress.getVisibility()!= View.VISIBLE){
            loading_progress.setVisibility(View.VISIBLE);
        }
    }

    /**
     * 隐藏家在狂
     */
    private void hideLoadingProgress(){
        if(loading_progress!=null && loading_progress.getVisibility()!=View.GONE){
            loading_progress.setVisibility(View.GONE);
        }
    }
    /**
     * 获取任务别表
     */
    public void getOrderCacheListDatasByNetwork(){
        orderTypeTableData  = orderDetailsCacheUtils.queryOrderTypeByOrderDurTime(strCurrentDate);
        hideLoadingProgress();
        if(orderTypeTableData!=null && !orderTypeTableData.isEmpty()){
            hideEmptyDatasView();
            orderCacheAdapter.setOrderDatas(orderTypeTableData);
        }else {
            showEmptyDatasView();
        }
    }

    /**
     * 显示空数据view
     */
    public void showEmptyDatasView(){
        if(view_empty!=null){
            view_empty.setVisibility(View.VISIBLE);
        }
    }

    /**
     * 隐藏空数据view
     */
    public void hideEmptyDatasView(){
        if(view_empty!=null){
            view_empty.setVisibility(View.GONE);
        }
    }
    @Override
    public void getTimerOrderdMyBroadcastReceiver(String action) {
        KLog.e("----------getTimerOrderdMyBroadcastReceiver-----------:" + action);
        if ("android.myapp.timer.orders.auto.start".equals(action)) {
            //结束本页面
            finish();
        }
    }
}
